﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Universum.Model.Services.Blog;
using Universum.Controllers;
using System.Web.Mvc;
using Universum.Model.Domain.Blogs;
using Universum.Infrastructure.Utils;
using Moq;
using Universum.Model.Services;

namespace Universum.Unit.Tests.Controllers.BlogArticleBehaviour
{
	[TestClass]
	public class When_creating_a_new_blogArticle : with_user_logged_and_blog
	{
		public When_creating_a_new_blogArticle()
		{

		}
		[TestInitialize]
		public void establishes_context()
		{
			base.EstablishContext();
		}
		[TestMethod]
		public void should_create_a_new_item()
		{
			// arrange
			//var blogArticleService = new BlogArticleServiceImpl(
			//    Repository,
			//    Principal,
			//    new BlogServiceImpl(Repository));
			var blogArticleServiceMock = new Mock<IBlogArticleService>();
			blogArticleServiceMock.Setup(b => b.Create()).Returns(
				()=>new BlogArticle
				{
					BlogId = Guid.Empty
				}).Verifiable();
			blogArticleServiceMock.Setup(b => b.SaveOrUpdate(It.IsAny<BlogArticle>())).Verifiable();

			var friendlyUrlService = new Mock<IFriendlyUrlService>();
			friendlyUrlService.Setup(it => it.CreateSlugFrom(It.IsAny<String>())).Returns("slug-for-rent").Verifiable();
			// act
			
			var blogArticleController = new BlogArticleController(Principal,
				blogArticleServiceMock.Object,
				friendlyUrlService.Object);
			var form = new FormCollection();
				
			form.Add(MemberUtil<BlogArticle>.MemberName(a => a.Title), "aa");
			var result = blogArticleController.Create(form);
			// assert
			blogArticleServiceMock.VerifyAll();
			result.should_not_be_null();
			result.should_be_of_type<RedirectToRouteResult>();
			result.Cast<RedirectToRouteResult>().RouteValues["Controller"].Equals("BlogArticle");
			result.Cast<RedirectToRouteResult>().RouteValues["Action"].Equals("Details");
		}
	}
}
